<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:body>
        <ui:composition template="/templates/layout.xhtml">
            <ui:define name="content">
                <h:form id="formId">
                    <p:panel id="panelId" header="รายงานข้อมูลความเสี่ยง" style="font-size: small; border: 0; padding: 0px; margin: 0px"/>
                    <p:focus context="panelId"/>
                    <p:fieldset legend="ระบุวันที่ต้องการค้นหา" style="text-align: left; margin-bottom: 10px">
                        <div align="center">
                            <p:panelGrid style="width: 600px; text-align: left; margin-bottom: 10px">
                                <p:row>
                                    <p:column style="text-align: right;">
                                        <h:outputLabel value="From : " for="popupButtonCalFrom"/>
                                    </p:column>
                                    <p:column style="text-align: left;">
                                        <p:calendar value="#{riskSummaryBean.selectedDateTimeFrom}" id="popupButtonCalFrom" 
                                                    maxdate="#{riskSummaryBean.maxDate}"
                                                    mindate="#{riskSummaryBean.fromMinDate}"
                                                    readonlyInput="true" showOn="button" effectDuration="1" pattern="MM/dd/yyyy">
                                            <p:ajax event="dateSelect" update="popupButtonCalFrom,popupButtonCalTo,riskView" listener="#{riskSummaryBean.handleDateSelectFrom}"/>
                                        </p:calendar>
                                    </p:column>
                                    <p:column style="text-align: right;">
                                        <h:outputLabel value="To : " for="popupButtonCalTo"/>
                                    </p:column>
                                    <p:column style="text-align: left;">
                                        <p:calendar value="#{riskSummaryBean.selectedDateTimeTo}" id="popupButtonCalTo" 
                                                    maxdate="#{riskSummaryBean.maxDate}"
                                                    mindate="#{riskSummaryBean.toMinDate}"
                                                    readonlyInput="true" showOn="button" effectDuration="1" pattern="MM/dd/yyyy">
                                            <p:ajax event="dateSelect" update="popupButtonCalFrom,popupButtonCalTo,riskView" listener="#{riskSummaryBean.handleDateSelectTo}"/>
                                        </p:calendar>
                                    </p:column>
                                </p:row>
                            </p:panelGrid>
                        </div>
                    </p:fieldset>

                    <p:dataTable id="riskView" var="items" rowIndexVar="rowIndex" value="#{riskSummaryBean.summaryLevels}" 
                                 emptyMessage="ไม่พบข้อมูลที่ค้นหา" style="text-align: center;" styleClass="borderGrid">

                        <f:facet name="header">Risk Statistics</f:facet>

                        <p:columnGroup type="header">
                            <p:row>
                                <p:column rowspan="2" headerText="ฝ่ายงาน"/>
                                <p:column rowspan="2" headerText="รวม" />
                                <p:column colspan="9" headerText="ระดับความรุนแรง" />
                            </p:row>

                            <p:row>
                                <p:column headerText="A" /><p:column headerText="B" />
                                <p:column headerText="C" /><p:column headerText="D" />
                                <p:column headerText="E" /><p:column headerText="F" />
                                <p:column headerText="G" /><p:column headerText="H" />
                                <p:column headerText="I" />
                            </p:row>
                        </p:columnGroup>

                        <p:column style="text-align: left">
                            <p:commandLink actionListener="#{riskSummaryBean.handleCmdLink(items.workgroupId)}" 
                                           update="riskView" style="text-decoration: none">
                                <h:outputText value="#{items.workgroupName}" />
                            </p:commandLink>
                        </p:column>
                        <p:column>#{items.summary}</p:column>
                        <p:column>
                            <p:commandLink disabled="#{!(items.categoryA != 0)}" ajax="true"
                                           actionListener="#{riskSummaryBean.injectLevelId(items.workgroupId, items.idCategoryA)}">
                                <h:outputText value="#{items.categoryA}" />
                            </p:commandLink>
                        </p:column>
                        <p:column>
                            <p:commandLink disabled="#{!(items.categoryB != 0)}" ajax="true"
                                           actionListener="#{riskSummaryBean.injectLevelId(items.workgroupId, items.idCategoryB)}">
                                <h:outputText value="#{items.categoryB}" />
                            </p:commandLink>
                        </p:column>
                        <p:column>
                            <p:commandLink disabled="#{!(items.categoryC != 0)}" ajax="true"
                                           actionListener="#{riskSummaryBean.injectLevelId(items.workgroupId, items.idCategoryC)}">
                                <h:outputText value="#{items.categoryC}" />
                            </p:commandLink>
                        </p:column>
                        <p:column>
                            <p:commandLink disabled="#{!(items.categoryD != 0)}" ajax="true"
                                           actionListener="#{riskSummaryBean.injectLevelId(items.workgroupId, items.idCategoryD)}">
                                <h:outputText value="#{items.categoryD}" />
                            </p:commandLink>
                        </p:column>
                        <p:column>
                            <p:commandLink disabled="#{!(items.categoryE != 0)}" ajax="true"
                                           actionListener="#{riskSummaryBean.injectLevelId(items.workgroupId, items.idCategoryE)}">
                                <h:outputText value="#{items.categoryE}" />
                            </p:commandLink>
                        </p:column>
                        <p:column>
                            <p:commandLink disabled="#{!(items.categoryF != 0)}" ajax="true"
                                           actionListener="#{riskSummaryBean.injectLevelId(items.workgroupId, items.idCategoryF)}">
                                <h:outputText value="#{items.categoryF}" />
                            </p:commandLink>
                        </p:column>
                        <p:column>
                            <p:commandLink disabled="#{!(items.categoryG != 0)}" ajax="true"
                                           actionListener="#{riskSummaryBean.injectLevelId(items.workgroupId, items.idCategoryG)}">
                                <h:outputText value="#{items.categoryG}" />
                            </p:commandLink>
                        </p:column>
                        <p:column>
                            <p:commandLink disabled="#{!(items.categoryH != 0)}" ajax="true"
                                           actionListener="#{riskSummaryBean.injectLevelId(items.workgroupId, items.idCategoryH)}">
                                <h:outputText value="#{items.categoryH}" />
                            </p:commandLink>
                        </p:column>
                        <p:column>
                            <p:commandLink disabled="#{!(items.categoryI != 0)}" ajax="true"
                                           actionListener="#{riskSummaryBean.injectLevelId(items.workgroupId, items.idCategoryI)}">
                                <h:outputText value="#{items.categoryI}" />
                            </p:commandLink>
                        </p:column>
                    </p:dataTable>
                </h:form>
            </ui:define>
        </ui:composition>
    </h:body>
</html>